package com.guigu.eduservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.common.utils.R;
import com.guigu.eduservice.entity.EquipmentType;
import com.guigu.eduservice.service.EquipmentTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 设备类型表（支持多级分类，管理平台所有二手机械类型） 前端控制器
 * </p>
 *
 * @author Xiaosong
 * @since 2025-10-09
 */
@RestController
@RequestMapping("/advertisement")
public class EquipmentTypeController {
        @Autowired
    private EquipmentTypeService equipmentTypeService;
        //根据id查询类型名称
    @GetMapping("getEquipmentTypeName/{typeId}")
    public R getEquipmentTypeName(@PathVariable Long typeId){
        EquipmentType equipmentType = equipmentTypeService.getById(typeId);
        return R.ok().data("typeName",equipmentType.getTypeName());
    }
        //条件查询一级分类
    @GetMapping("list")
    public R list(){
        QueryWrapper<EquipmentType> queryWrapper = new QueryWrapper<>();
        queryWrapper.isNull("parent_id");
        System.out.println(equipmentTypeService.list(queryWrapper));
        return R.ok().data("list",equipmentTypeService.list(queryWrapper));
    }
    /**
     * 前台-查询所有1级设备类型
     * */
    @GetMapping("/selectallequipmentType_PC")
    public R selectallequipmentType_PC(){

        QueryWrapper<EquipmentType> equipmentTypeQueryWrapper = new QueryWrapper<>();
        equipmentTypeQueryWrapper.eq("status",1);
        equipmentTypeQueryWrapper.isNull("parent_id");

        List<EquipmentType> list = equipmentTypeService.list(equipmentTypeQueryWrapper);

        return R.ok().data("list",list);
    }
    /**
     * 前台-查询前8个1级设备类型
     * */
    @GetMapping("/selectfrontqiequipmentType_PC")
    public R selectfrontqiequipmentType_PC(){

        QueryWrapper<EquipmentType> equipmentTypeQueryWrapper = new QueryWrapper<>();
        equipmentTypeQueryWrapper.eq("status",1);
        equipmentTypeQueryWrapper.isNull("parent_id");
        equipmentTypeQueryWrapper.orderByDesc("sort");
        equipmentTypeQueryWrapper.last("LIMIT 8");

        List<EquipmentType> list = equipmentTypeService.list(equipmentTypeQueryWrapper);

        return R.ok().data("list",list);
    }
    // 前台-查询二级分类三级分类
    @GetMapping("/queryfrontshiEquipmentType/{parentId}")
    public R queryfrontshiEquipmentType(@PathVariable("parentId") Long parentId){
        QueryWrapper<EquipmentType> equipmentTypeQueryWrapper = new QueryWrapper<>();
        equipmentTypeQueryWrapper.eq("status",1);
        equipmentTypeQueryWrapper.eq("parent_id",parentId);
        List<EquipmentType> list = equipmentTypeService.list(equipmentTypeQueryWrapper);
        return R.ok().data("list",list);

    }
    /**
     * 前台-查询所有设备类型
     * */
    @GetMapping("/selectAllEquipmentTypeByPC")
    public R selectAllEquipmentTypeByPC(){

        QueryWrapper<EquipmentType> equipmentTypeQueryWrapper = new QueryWrapper<>();
        equipmentTypeQueryWrapper.eq("status",1);
        List<EquipmentType> list = equipmentTypeService.list(equipmentTypeQueryWrapper);

        return R.ok().data("list",list);
    }
}
